package cn.jekun.web.agent.action;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;

import cn.jekun.component.base.bean.SessionUser;
import cn.jekun.component.base.exceptions.TimeoutException;
import cn.jekun.component.core.action.ComponentCoreAction;
import cn.jekun.shop.web.bean.MemberSession;
import cn.jekun.web.shop.bean.WebUser;

/**
 * 代理商后台的基类Action
 * 
 * @author twj
 * 
 */
public class AgentBaseAction extends ComponentCoreAction{
	@Override
	protected void validateTimeout() throws TimeoutException {
		try{
		if (this.getSessionUser() == null) {
			throw new TimeoutException("超时退出，请重新登录");
		}
		}catch(Exception e){
			e.printStackTrace();
		}

	}
	
	/**
	 * 获取当前登录的用户
	 * @return
	 */
	@Override
	protected MemberSession getSessionUser(){
		return (MemberSession) this.request.getSession().getAttribute(SessionUser.SESSION_KEY);
	}
	
	/**
	 * 获取当前操作用户代码
	 */
	@Override
	public String getUserId() {
		String uid = this.getSessionUser().getUserId();
		return uid;
	}
	/**
	 * Date转字符串
	 * @param date
	 * @return
	 */
	protected String DateToString(Date date){
		
		// HH:mm:ss
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		
		try {
			return sdf.format(date);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
		}
		return "";
		
	}
	
	/**
	 * Date转字符串
	 * @param date
	 * @return
	 */
	protected String DateToDString(Date date){
		
		// HH:mm:ss
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		try {
			return sdf.format(date);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
		}
		return "";
		
	}

}
